﻿
using System.Linq;

namespace Moria
{
    public static class Extentions
    {
        public static int IndexOf<_type > (this _type[] src,_type item)
        {

            if (src.First() != null && src.First().Equals(item)) return 0;
            if (src.Last() != null && src.Last().Equals(item)) return src.Length-1;
            if ( src.Length > 1)
            {
                for (int i = 1; i < src.Length - 1;i++ )
                {
                    if (src[i] != null && src[i].Equals(item)) 
                        return i;
                }
            }
            return -1;
        }
        public static bool magik(this int chance)
        {
            return (Dice.RandInt(100) <= chance);
        }

        /* Converts stat num into string			-RAK-	*/
        public static string cnv_stat(this int stat)
        {
            if (stat > 18)
            {
                int part2 = stat - 18;
                if (part2 == 100) return "18/100";
                return part2.ToString("18/00");
                //return string.Format(" 18/{0:00}", part2);
            }
            return string.Format("{0}", stat);
        }

    }
}
